const targetMap = new WeakMap() // For storing the dependencies for each reactive object

// Save this code
function track(target, key) {
  let depsMap = targetMap.get(target) // Get the current depsMap for this target(reactive object - product)
  if (!depsMap) {
    targetMap.set(target, (depsMap = new Map())) // If it doesn't exist, create it
  }
  let dep = depsMap.get(key) // Get the dependency object for this peoperty - quantity
  if (!dep) {
    depsMap.set(key, (dep = new Set())) // If it doesn't exist, create it
  }
  dep.add(effect) // Add the effect to the dependency
}

// Run all the code I've saved
function trigger(target, key) {
  const depsMap = targetMap.get(target) // Does this object have any properties that have dependencies?
  if (!depsMap) {
    return // If no, return from the function immediately
  }
  let dep = depsMap.get(key) // Otherwise, check if this property has a dependency
  if (dep) {
    dep.forEach(effect => {
      effect()
    }) // Run those
  }
}